package com.corner.system.service.impl;

import com.corner.system.mapper.IoTData_1Mapper;
import com.corner.system.service.IoData_1Service;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDate;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * 用户 业务层处理
 * 
 * @author corner
 */
@Service
public class IoData_1ServiceImpl implements IoData_1Service
{
    private static final Logger log = LoggerFactory.getLogger(IoData_1ServiceImpl.class);

    @Autowired
    private IoTData_1Mapper ioData1Mapper;


    @Override
    public List<Map> getDataAndMonthOld(String deviceId, String selectCount) {
        List<Map> dataAndMonth = ioData1Mapper.getDataAndMonthOld(deviceId, selectCount);
        return dataAndMonth;
    }

    @Override
    public List<Map> getDataAndMonth(String deviceId, int selectCount) {

        List yearmonths = new ArrayList<>();
        LocalDate currentDate = LocalDate.now();
        for(int i = 0; i <= selectCount-1; i++){
            LocalDate currentDate1 = currentDate;
            if(i>0){
                currentDate1 = currentDate.minusMonths(i);
            }
            int currentyear = currentDate1.getYear();
            int currentmonthint = currentDate1.getMonthValue();
            String currentmonth = String.format("%02d", currentmonthint);
            String yearAndMonth = currentyear+"-"+currentmonth;
            yearmonths.add(yearAndMonth);
            System.out.println(yearAndMonth);
        }
        List<Map> dataAndMonth = ioData1Mapper.getDataAndMonth(yearmonths, deviceId);
        return dataAndMonth;
    }
}
